//
//  TF_LivingToolBtn.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/12/15.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_LivingToolBtn: UIButton {
    @objc public var redDotLayer:CAShapeLayer?
    //画小红点
 @objc public func drawRedDot()

    {
        
        if(self.redDotLayer==nil){
            self.clipsToBounds = false;
            
            let redDotLayerWidth = self.frame.size.width/5.0
            self.redDotLayer = CAShapeLayer()
            // 指定frame，
            self.redDotLayer!.frame = CGRect(x: 0, y:0, width:redDotLayerWidth , height: redDotLayerWidth)
            self.redDotLayer!.position = CGPoint(x: (self.frame.size.width/2)+(self.frame.size.width/2/2), y: ((self.frame.size.height/2)-(self.frame.size.height/2) + (redDotLayerWidth/2)))
            // 设置填充颜色
            self.redDotLayer!.fillColor = UIColor.red.cgColor
            // 设置线宽
            self.redDotLayer!.lineWidth = 1
            // 设置线的颜色
            self.redDotLayer!.strokeColor =  UIColor.red.cgColor
            // 使用UIBezierPath创建路径
            self.redDotLayer!.masksToBounds = true
            
            self.redDotLayer!.cornerRadius = self.redDotLayer!.frame.width/2;

            // 设置CAShapeLayer与UIBezierPath关联
          self.redDotLayer!.path = UIBezierPath.init(rect: CGRect(x: 0, y: 0, width: self.redDotLayer!.frame.size.width, height: self.redDotLayer!.frame.size.height)).cgPath
            
            self.redDotLayer!.strokeStart = 0.0
            self.redDotLayer!.strokeEnd =   1.0;
            // 将CAShaperLayer放到某个层上显示
            
        self.layer.addSublayer(self.redDotLayer!)
        }
            
            
    }
    //清除小红点
    @objc public func clearRedDot()
   {
   
     if  self.redDotLayer != nil {
         self.redDotLayer!.removeFromSuperlayer()
         self.redDotLayer = nil
     }
     

        
    }
}
